<?php

/* @var $this \yii\web\View */
/* @var $content string */

use backend\assets\AppAsset;
use yii\helpers\Html;

AppAsset::register($this);
?>
<?php $this->beginPage() ?>
    <!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
    <head>
        <meta charset="<?= Yii::$app->charset ?>">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
        <?= Html::csrfMetaTags() ?>
        <title>汤先生仓管系统</title>
        <?php $this->head() ?>
        <?php
        //use yii\helpers\Html;
        AppAsset::addCss($this,Yii::$app->request->baseUrl."static/plugins/bootstrap/css/bootstrap.min.css");
        AppAsset::addCss($this,Yii::$app->request->baseUrl."static/dist/css/font-awesome.min.css");
        AppAsset::addCss($this,Yii::$app->request->baseUrl."static/dist/css/ionicons.min.css");
        AppAsset::addCss($this,Yii::$app->request->baseUrl."static/dist/css/AdminLTE.min.css");
        AppAsset::addCss($this,Yii::$app->request->baseUrl."static/dist/css/skins/_all-skins.min.css");
        AppAsset::addCss($this,Yii::$app->request->baseUrl."static/plugins/daterangepicker/daterangepicker.css");
        AppAsset::addCss($this,Yii::$app->request->baseUrl."static/plugins/datepicker/datepicker3.css");
        AppAsset::addCss($this,Yii::$app->request->baseUrl."static/plugins/iCheck/all.css");
        AppAsset::addCss($this,Yii::$app->request->baseUrl."static/plugins/colorpicker/bootstrap-colorpicker.min.css");
        AppAsset::addCss($this,Yii::$app->request->baseUrl."static/plugins/timepicker/bootstrap-timepicker.min.css");
        AppAsset::addCss($this,Yii::$app->request->baseUrl."static/plugins/select2/select2.min.css");
        AppAsset::addCss($this,Yii::$app->request->baseUrl."static/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css");
        AppAsset::addCss($this,Yii::$app->request->baseUrl."static/plugins/iCheck/flat/blue.css");
        AppAsset::addCss($this,Yii::$app->request->baseUrl."static/plugins/fullcalendar/fullcalendar.min.css");
        AppAsset::addCss($this,Yii::$app->request->baseUrl."static/plugins/fullcalendar/fullcalendar.print.css");
        AppAsset::addCss($this,Yii::$app->request->baseUrl."static/plugins/ionslider/ion.rangeSlider.css");
        AppAsset::addCss($this,Yii::$app->request->baseUrl."static/plugins/ionslider/ion.rangeSlider.skinNice.css");
        AppAsset::addCss($this,Yii::$app->request->baseUrl."static/plugins/bootstrap-slider/slider.css");
        AppAsset::addCss($this,Yii::$app->request->baseUrl."static/plugins/morris/morris.css");
        AppAsset::addCss($this,Yii::$app->request->baseUrl."static/plugins/jvectormap/jquery-jvectormap-1.2.2.css");

        ?>
        <style>
            .iframe_show{
                display: block;
                height: 100%;
            }
            .iframe_hide{
                display: none;
            }
            .menu_click{
                cursor: pointer;
            }
            .menu_url span{
                text-align: center;
            }

            .tabs-page{
                height: 40px;
                overflow: hidden;

            }
        </style>
    </head>
<body class="sidebar-mini ajax-template skin-blue fixed">
<?php $this->beginBody() ?>
<div class="wrapper">
    <header class="main-header">
        <!-- Logo -->
        <a href="javascript:void(0)" class="logo">
            <!-- mini logo for sidebar mini 50x50 pixels -->
            <span class="logo-mini"><b>汤</b>家</span>
            <!-- logo for regular state and mobile devices -->
            <span class="logo-lg"><b> <?php echo $this->params['menuTitle']?></b></span>
        </a>
        <!-- Header Navbar: style can be found in header.less -->
        <nav class="navbar navbar-static-top">
            <!-- Sidebar toggle button-->
            <a href="#" class="sidebar-toggle" data-toggle="offcanvas" role="button">
                <span class="sr-only">切换导航</span>
            </a>

            <div class="navbar-custom-menu">
                <ul class="nav navbar-nav">

                    <li class="dropdown user user-menu">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                            <?= Html::img(Yii::$app->request->baseUrl.'/static/dist/img/user2-160x160.jpg',array('class'=>'user-image','alt'=>'user image'));?>
                            <!--<img src="dist/img/user2-160x160.jpg" class="user-image" alt="User Image">-->
                            <span class="hidden-xs"><?php echo $this->params['username']?></span>
                        </a>
                        <ul class="dropdown-menu">
                            <!-- User image -->
                            <li class="user-header">
                                <?= Html::img(Yii::$app->request->baseUrl.'/static/dist/img/user2-160x160.jpg',array('class'=>'img-circle','alt'=>'user image'));?>
                                <!--<img src="dist/img/user2-160x160.jpg" class="img-circle" alt="User Image">-->
                                <p><?php echo $this->params['username']?></p>
                                <p>角色：<?php echo $this->params['roleName']?></p>
                            </li>
                            <!-- Menu Footer-->
                            <li class="user-footer">
								<div class="pull-left">
								    <a class="navTab menu_click btn btn-default btn-flat" data-title="修改密码" url="/sys-user/update-password">修改密码</a>
								</div>
                                <div class="pull-right">
                                    <a href="/login/login-out" id="a_logout" class="btn btn-default btn-flat">退出</a>
                                </div>
                            </li>
                        </ul>
                    </li>
                    <!-- Control Sidebar Toggle Button -->
                    <li>
                        <a href="#" data-toggle="control-sidebar"><i class="fa fa-gears"></i></a>
                    </li>
                </ul>
            </div>
        </nav>
    </header>
<aside class="main-sidebar" style="width: 180px">
    <!-- sidebar: style can be found in sidebar.less -->
<section class="sidebar">
    <!-- Sidebar user panel -->
    <div class="user-panel">
        <div class="pull-left image">
            <?= Html::img(Yii::$app->request->baseUrl.'/static/dist/img/user2-160x160.jpg',array('class'=>'img-circle','alt'=>'user image'));?>
            <!--<img src="dist/img/user2-160x160.jpg" class="img-circle" alt="User Image">-->
        </div>
        <div class="pull-left info">
            <p><?php echo $this->params['username']?></p>
        </div>
    </div>
    <!-- sidebar menu: : style can be found in sidebar.less -->
    <ul class="sidebar-menu">
    <li class="header">主导航</li>
    <!--系统管理-->
<?php
$menu_lists = $this->params['menu_list'];
if(!empty($menu_lists)){
foreach($menu_lists as $value){
?>
    <li class="treeview">
    <a href="#">
        <i class="fa fa-<?=$value['icon']?>"></i> <span><?= $value['name']?></span>
            <span class="pull-right-container">
              <i class="fa fa-angle-left pull-right"></i>
            </span>
    </a>
    <?php if(!empty($value['child'])){?>
        <ul class="treeview-menu">
        <?php
        $menu_child = $value['child'];
        foreach($menu_child as $val){
            ?>
            <?php if(empty($val['child'])){?>
                <?php if($val['type'] == 0){?>
                    <li class="active">
                        <a class="navTab" href="#" data-title="<?= $val['name']?>">
                            <i class="fa fa-<?= $val['icon']?>"></i> <?= $val['name']?> </a>
                    </li>
                <?php }else{?>
                <li class="active">
                    <a class="navTab menu_click" data-title="<?= $val['name']?>" url="<?= $val['menu_name']?>">
                        <i class="fa fa-<?= $val['icon']?>"></i> <?= $val['name']?> </a>
                </li>
                <?php }?>
            <?php }else{?>
                <li class="treeview">
                <a href="#"><i class="fa fa-<?= $val['icon']?>"></i><span><?= $val['name']?></span><span class="pull-right-container"><i class="fa fa-angle-left pull-right"></i></span></a>
                <ul class="treeview-menu">
                <?php
                $menu_child_child = $val['child'];
                foreach($menu_child_child as $vale){
                    ?>
                    <li><a class="menu_click" data-title="<?= $vale['name']?>" url="<?= $vale['menu_name']?>"><i class="fa fa-<?= $vale['icon']?>"></i><?= $vale['name']?></a></li>
                <?php }?>
                </ul>
                </li>
            <?php }?>
        <?php }?>
        </ul>
    <?php }else{?>
    <?php }?>
    </li>
<?php }}?>
    </ul>
    </section>
    <!-- /.sidebar -->
    </aside>
    <div class="content-wrapper" style="margin-left: 180px">
        <section class="content-header-navtabs">
            <div class="tabs-page">
                <ul class="tabs-list clearfix" id="navTabs">
                    <li class="menu_url active" data-url="/site/home"><span>系统主页</span></li>
                </ul>
                <a href="javascript:void(0);" class="prev fa fa-step-backward b1"></a>
                <a href="javascript:void(0);" class="next fa fa-step-forward b1"></a>
            </div>
            <div class="context-menu" id="contextMenu">
                <ul class="ct-nav">
                    <li rel="reload">刷新标签页</li>
                    <li rel="closeCurrent">关闭标签页</li>
                </ul>
            </div>
        </section>
        <!-- Main content -->
        <section class="" id="content">
            <div class="iframe_show"><iframe src="/site/home" scrolling="yes" frameborder="0" height="100%" width="100%"></iframe></div>
        </section>
    </div>

    <footer class="main-footer">
        <div class="pull-right hidden-xs">
            <b>Version</b> <?php echo $this->params['verNumber']?>
        </div>
        <strong><?php echo $this->params['verInfo']?></strong>
    </footer>

    <!-- Control Sidebar -->
    <aside class="control-sidebar control-sidebar-dark">
        <!-- Create the tabs -->
        <ul class="nav nav-tabs nav-justified control-sidebar-tabs">
            <li><a href="#control-sidebar-home-tab" data-toggle="tab"><i class="fa fa-home"></i></a></li>
            <li><a href="#control-sidebar-settings-tab" data-toggle="tab"><i class="fa fa-gears"></i></a></li>
        </ul>
        <!-- Tab panes -->
        <div class="tab-content">
            <!-- Home tab content -->
            <div class="tab-pane" id="control-sidebar-home-tab">
            </div>
            <!-- /.tab-pane -->
        </div>
    </aside>
    <!-- /.control-sidebar -->
    <!-- Add the sidebar's background. This div must be placed
         immediately after the control sidebar -->
    <div class="control-sidebar-bg"></div>

    </div>

    <div id="loading" class="loading-panel">
        <div class="box">
            <i class="fa fa-refresh fa-spin"></i>
    <span class="tip">
       正在加载 · · ·
    </span>
        </div>
    </div>

    <script type="text/javascript">
        <?php $this->beginBlock('js') ?>
        var url = '/public/logout';
        var _csrf = "<?= Yii::$app->request->csrfToken ?>";
        $('#a_logout').click(function(){
            $.post(url,{_csrf:_csrf},function success(data){
                if(data.status){
                    alert(data.msg);
                    window.location.href = data.url;
                }else{
                    alert(data.msg);
                    window.location.href = data.url;
                }
            },'json');
        })

        $('.menu_click').click(function(){

            var btns = $(".b1");
            var src_url = $(this).attr('url');
            var check_number = 1;
            //判断对应url的iframe是否已经打开过
            $('iframe').each(function(){
                var iframe_url_check = $(this).attr('src');
                if(iframe_url_check == src_url){
                    if($(this).parent().hasClass('iframe_hide')){
                        $(this).parent().removeClass('iframe_hide');
                        $(this).parent().addClass('iframe_show');
                    }
                    check_number = 0;
                }else{
                    if($(this).parent().hasClass('iframe_show')){
                        $(this).parent().removeClass('iframe_show');
                        $(this).parent().addClass('iframe_hide');
                    }
                }
            });

            //已经打开过url对应的iframe
            if(check_number == 0){
                //显示对应的tab标签
                navEach(src_url);
                //回滚找到对应的标签
                if(btns){
                    $("#navTabs").animate({
                        "marginLeft":0+"px"
                    });
                }
                return false;
            }

            var menu_title = $(this).attr('data-title');

            $('#navTabs li').each(function(){
                $(this).removeClass('active');
            });

            //添加tab标签
            $('#navTabs').append('<li class="menu_url active" data-url="'+src_url+'"><span>'+menu_title+'</span></li>');

            //tab标签左右箭头显示
            var tabWarp = $('#navTabs').parent().width();
            var ulWidth = $('#navTabs').width();
                ulWidth>tabWarp?ulWidth=tabWarp:ulWidth;

            var liLength = $(".menu_url").length;
            var sum = $(".menu_url").eq(0).width();
            var indexlist = Math.floor( ulWidth/sum);
            var liSize = parseInt(liLength*sum);

           /* var btns = $(".b1");*/

            if(liSize>ulWidth){
                btns.show();
            }
            //tab新增超出可视滚动
            if(liLength>indexlist){
                var scrollI = parseInt(liSize/sum);
                var scrollLeft = scrollI-indexlist;
                $("#navTabs").animate({
                    "marginLeft":-(scrollLeft*sum)+"px"
                });
            }
            //隐藏当前iframe,打开新的iframe
            $('iframe').each(function(){
                $(this).parent().removeClass('iframe_show');
                $(this).parent().addClass('iframe_hide');
            })
            $('#content').append('<div class="iframe_show" ><iframe src="'+src_url+'" scrolling="yes" frameborder="0" height="100%" width="100%"></iframe></div>');
        });

        //点击tab的时候切换iframe
        $('ul').delegate('.menu_url','click',function(){

            $('#navTabs li').each(function(){
                $(this).removeClass('active');
            });
            $(this).addClass('active');

            var check_url = $(this).attr('data-url');
            $('iframe').each(function(){
                var iframe_url = $(this).attr('src');

                if(iframe_url == check_url){
                    if($(this).parent().hasClass('iframe_hide')){
                        $(this).parent().removeClass('iframe_hide');
                        $(this).parent().addClass('iframe_show');
                    }
                }else{
                    if($(this).parent().hasClass('iframe_show')){
                        $(this).parent().removeClass('iframe_show');
                        $(this).parent().addClass('iframe_hide');
                    }
                }
            })
        });
        //右键tab操作
        $('.ct-nav > li').click(function(){
            var li_text = $(this).attr('rel');
            var li_length = $(this).parent().parent().attr('is');
            var le_url = $('#navTabs li').eq(li_length).attr('data-url');
            //刷新
            if(li_text == 'reload'){

                //刷新当前的iframe
                if($('#navTabs li').eq(li_length).hasClass('active')){
                    $('iframe').each(function(){
                        var iframe_url = $(this).attr('src');

                        if(iframe_url == le_url){
                            $(this).attr('src',le_url);
                        }
                    })
                }else{
                    //刷新指定的iframe
                    navEach(le_url);

                    $('iframe').each(function(){
                        var iframe_url = $(this).attr('src');

                        if(iframe_url == le_url){
                            if($(this).parent().hasClass('iframe_hide')){
                                $(this).parent().removeClass('iframe_hide');
                                $(this).parent().addClass('iframe_show');
                                $(this).attr('src',le_url);
                            }
                        }else{
                            if($(this).parent().hasClass('iframe_show')){
                                $(this).parent().removeClass('iframe_show');
                                $(this).parent().addClass('iframe_hide');
                            }
                        }
                    })

                }
            }
            //关闭iframe
            if(li_text == 'closeCurrent'){

                var le_index = $('#navTabs li').eq(li_length).prev().index();
                var li_length_count = $('#navTabs li').length;
                if(eval(li_length_count) == 1){ //只有一个iframe的时候无法关闭
                    return true;
                }else{
                    var find_url;
                    if(eval(le_index) > -1){
                        $('#navTabs li').eq(li_length).prev().addClass('active');
                        find_url = $('#navTabs li').eq(li_length).prev().attr('data-url');
                    }else{
                        $('#navTabs li').eq(li_length).next().addClass('active');
                        find_url = $('#navTabs li').eq(li_length).next().attr('data-url');
                    }

                    $('#navTabs li').eq(li_length).remove();
                    navEach(find_url);

                    $('iframe').each(function(){
                        var iframe_url = $(this).attr('src');

                        if(iframe_url == le_url){
                            $(this).parent().remove();
                        }else{
                            if(iframe_url == find_url){
                                if($(this).parent().hasClass('iframe_hide')){
                                    $(this).parent().removeClass('iframe_hide');
                                    $(this).parent().addClass('iframe_show');
                                }
                            }else{
                                if($(this).parent().hasClass('iframe_show')){
                                    $(this).parent().removeClass('iframe_show');
                                    $(this).parent().addClass('iframe_hide');
                                }
                            }
                        }

                    })
                }
            }
        });

        function navEach(url){
            $('#navTabs li').each(function(){
                $(this).removeClass('active');
                var li_url = $(this).attr('data-url');
                if(li_url == url){
                    $(this).addClass('active');
                }
            })
        }

        <?php $this->endBlock() ?>
        <?php $this->registerJs($this->blocks['js'], \yii\web\View::POS_END); ?>
    </script>
    <?php
    AppAsset::addJs($this,Yii::$app->request->baseUrl."static/plugins/jQuery/jquery-2.2.3.min.js");
    AppAsset::addJs($this,Yii::$app->request->baseUrl."static/plugins/bootstrap/js/bootstrap.min.js");
    AppAsset::addJs($this,Yii::$app->request->baseUrl."static/plugins/fastclick/fastclick.js");
    AppAsset::addJs($this,Yii::$app->request->baseUrl."static/plugins/slimScroll/jquery.slimscroll.min.js");
    AppAsset::addJs($this,Yii::$app->request->baseUrl."static/dist/js/app.js");

    AppAsset::addJs($this,Yii::$app->request->baseUrl."static/plugins/jQueryUI/jquery-ui.min.js");
    AppAsset::addJs($this,Yii::$app->request->baseUrl."static/plugins/raphael/raphael.min.js");
    AppAsset::addJs($this,Yii::$app->request->baseUrl."static/plugins/morris/morris.min.js");
    AppAsset::addJs($this,Yii::$app->request->baseUrl."static/plugins/sparkline/jquery.sparkline.min.js");
    AppAsset::addJs($this,Yii::$app->request->baseUrl."static/plugins/jvectormap/jquery-jvectormap-1.2.2.min.js");
    AppAsset::addJs($this,Yii::$app->request->baseUrl."static/plugins/jvectormap/jquery-jvectormap-world-mill-en.js");
    AppAsset::addJs($this,Yii::$app->request->baseUrl."static/plugins/knob/jquery.knob.js");
    AppAsset::addJs($this,Yii::$app->request->baseUrl."static/plugins/moment/moment.min.js");
    AppAsset::addJs($this,Yii::$app->request->baseUrl."static/plugins/daterangepicker/daterangepicker.js");
    AppAsset::addJs($this,Yii::$app->request->baseUrl."static/plugins/datepicker/bootstrap-datepicker.js");
    AppAsset::addJs($this,Yii::$app->request->baseUrl."static/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js");
    AppAsset::addJs($this,Yii::$app->request->baseUrl."static/plugins/slimScroll/jquery.slimscroll.min.js");
    AppAsset::addJs($this,Yii::$app->request->baseUrl."static/plugins/chartjs/Chart.min.js");
    AppAsset::addJs($this,Yii::$app->request->baseUrl."static/plugins/flot/jquery.flot.min.js");
    AppAsset::addJs($this,Yii::$app->request->baseUrl."static/plugins/flot/jquery.flot.resize.min.js");
    AppAsset::addJs($this,Yii::$app->request->baseUrl."static/plugins/flot/jquery.flot.pie.min.js");
    AppAsset::addJs($this,Yii::$app->request->baseUrl."static/plugins/flot/jquery.flot.categories.min.js");
    AppAsset::addJs($this,Yii::$app->request->baseUrl."static/plugins/iCheck/icheck.min.js");
    AppAsset::addJs($this,Yii::$app->request->baseUrl."static/plugins/select2/select2.full.min.js");
    AppAsset::addJs($this,Yii::$app->request->baseUrl."static/plugins/input-mask/jquery.inputmask.js");
    AppAsset::addJs($this,Yii::$app->request->baseUrl."static/plugins/input-mask/jquery.inputmask.date.extensions.js");
    AppAsset::addJs($this,Yii::$app->request->baseUrl."static/plugins/input-mask/jquery.inputmask.extensions.js");
    AppAsset::addJs($this,Yii::$app->request->baseUrl."static/plugins/daterangepicker/daterangepicker.js");
    AppAsset::addJs($this,Yii::$app->request->baseUrl."static/plugins/datepicker/bootstrap-datepicker.js");
    AppAsset::addJs($this,Yii::$app->request->baseUrl."static/plugins/colorpicker/bootstrap-colorpicker.min.js");
    AppAsset::addJs($this,Yii::$app->request->baseUrl."static/plugins/timepicker/bootstrap-timepicker.min.js");
    AppAsset::addJs($this,Yii::$app->request->baseUrl."static/plugins/ionslider/ion.rangeSlider.min.js");
    AppAsset::addJs($this,Yii::$app->request->baseUrl."static/plugins/bootstrap-slider/bootstrap-slider.js");
    ?>
    <?php $this->endBody() ?>
    </body>
    </html>
    <?php $this->endPage() ?>